package com.kate.mall.product.queue;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import org.bouncycastle.cert.ocsp.Req;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 新梦想.陈超
 * @version 2021.2
 * @Description: {TODO}
 * @date 2022/7/15 下午4:43
 */

public class RequestQueue {
    /**
     * 阻塞队列集合
     */
    private List<BlockingQueue<Request>> queueList = new ArrayList<>();
    /**
     * 定义保存读写的标记  1：写 --true  2：读---false
     */
    public Map<Integer,Boolean> flagMap = new ConcurrentHashMap<>();
    /**
     * 向queueList中添加阻塞队列
     */
    public void addQueue(BlockingQueue<Request> queue){
        queueList.add(queue);
    }
    /**
     * 从queueList中根据index取一个阻塞队列
     */
    public BlockingQueue<Request> index(int index){
        return queueList.get(index);
    }

    /**
     * 返回阻塞队列的size
     */
    public int getSize(){
        return queueList.size();
    }

    private RequestQueue(){}
    /**
     * 单例模式：静态内部类
     */
    private static class Singleton{
        public static RequestQueue requestQueue = new RequestQueue();
    }
    public static RequestQueue queue(){
        return Singleton.requestQueue;
    }

    public static void main(String[] args) {
        System.out.println(RequestQueue.queue());
        System.out.println(RequestQueue.queue());
        System.out.println(RequestQueue.queue());
        System.out.println(RequestQueue.queue());
    }

}